﻿using System;
using System.Globalization;

namespace Blackbird.Common.Logging
{
    public enum LogEntryType
    {
        Debug,
        Info,
        Warning,
        Error
    }

    [Serializable]
    public class LogEntry : IComparable<LogEntry>
    {
        private readonly LogEntryType _logEntryType;

        private readonly string _messageText;

        private DateTime _timestamp;

        public LogEntry(LogEntryType type, string message)
        {
            _logEntryType = type;
            _messageText = message;
            _timestamp = DateTime.Now;
        }

        public LogEntry(LogEntryType type, string format, params object[] args)
            : this(type, string.Format(CultureInfo.CurrentUICulture, format, args))
        {
        }

        public LogEntryType LogEntryType
        {
            get { return _logEntryType; }
        }

        public string MessageText
        {
            get { return _messageText; }
        }

        public DateTime Timestamp
        {
            get { return _timestamp; }
        }

        #region IComparable<LogEntry> Members

        public int CompareTo(LogEntry other)
        {
            return _timestamp.CompareTo(other.Timestamp);
        }

        #endregion

        public override string ToString()
        {
            return string.Format("{0} {1}: {2}", _logEntryType.ToString(), _timestamp.ToShortTimeString(), MessageText);
        }
    }
}